import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;


public class TCPEchoClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try{
			Socket s = new Socket("localhost",2014); //ket noi den server
			InputStream is = s.getInputStream(); //lay inputStream
			OutputStream os = s.getOutputStream(); //lay outputStream
			for(int i='0';i<='9';i++){ //gui '0'->'9' den cho server
				os.write(i); //gui 1 ki tu den server
				int ch = is.read(); //cho nhan 1 ki tu tu server
				System.out.println((char)ch); //in ki tu nhan duoc ra man hinh
			}
		}
		catch(IOException ie){
			System.out.println("Loi: Khong tao duoc socket");
		}//catch
	}//main

}
